package com.weiyuwqj.admin.controller.admin.asset;

import com.weiyuwqj.admin.controller.base.BaseController;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.BusAssetPackagePlan;
import com.weiyuwqj.api.model.convert.ModelConvert;
import com.weiyuwqj.api.model.vo.AssetInvestVo;
import com.weiyuwqj.api.service.BusAssetInvestService;
import com.weiyuwqj.api.service.BusAssetPackagePlanService;
import com.weiyuwqj.api.util.ExcelUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/29.
 */
@Controller
@RequestMapping("/admin/assetPackage")
public class BusAssetPackagePlanController extends BaseController {

    @Autowired
    private BusAssetPackagePlanService busAssetPackagePlanService;

    @Autowired
    private BusAssetInvestService assetInvestService;


    /**
     * 查询资产包计划列表
     *
     * @param p                   分页参数
     * @param busAssetPackagePlan 资产包计划对象
     * @return
     */
    @ResponseBody
    @RequestMapping("/getPackagePlanList")
    public Object getPackagePlanList(Paginator p, BusAssetPackagePlan busAssetPackagePlan) {
        return busAssetPackagePlanService.getPackagePlanList(p, busAssetPackagePlan);
    }

    /**
     * 获取匹配前投资列表
     */
    @ResponseBody
    @RequestMapping("/listInvestBeforeMatch")
    public Object listInvestBeforeMatch(Integer packagePlanId) {
        return busAssetPackagePlanService.listInvestBeforeMatch(packagePlanId);
    }

//    /**
//     * 匹配
//     *
//     * @param matchJson
//     * @param packagePlanId
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping("/investMatch")
//    public Object investMatch(String matchJson, Integer packagePlanId) {
//        busAssetPackagePlanService.investMatch(matchJson, packagePlanId);
//        return Message.OK;
//    }


    /**
     * 计划投资列表
     * @param p 分页参数
     * @param itemName 项目名
     * @param command 用户名/真实名
     * @param packageName 包名
     * @param packagePlanName 包计划名
     * @param beginDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @ResponseBody
    @RequestMapping("/listPackagePalnInvest")
    public Object listPackagePalnInvest(Paginator p, String itemName,
                                        String command,
                                        String packageName,
                                        String packagePlanName,
                                        String beginDate,
                                        String endDate) {
        Map map = new HashMap();
        map.put("itemName", itemName);
        map.put("command", command);
        map.put("packageName", packageName);
        map.put("packagePlanName", packagePlanName);
        map.put("beginDate", beginDate);
        map.put("endDate", endDate);
        return assetInvestService.getList(p, map);
    }

//    //导出投资信息
//    @ResponseBody
//    @RequestMapping("/excel")
//    public Object excelInvest(HttpServletRequest request,
//                              String command,
//                              String packageName,
//                              String packagePlanName,
//                              String beginDate,
//                              String endDate) {
//        String[] cArray = {"项目名称", "用户名", "真实名", "手机号", "包名", "计划名","投资信息","订单号", "待收金额","期限","债转状态","添加时间","利率信息"};
//        String[] eArray = {"Username", "Mobile", "Realname", "Income", "InviteUsername","InviteMobile","InviteRealname", "ItemName", "InvestDealAmount","ItemCycle","Addtime"};
//        ModelConvert[] converts = {null, null, null, null, null, null, null ,null,null, null,null,null,null};
//
//        List<String> cList = Arrays.asList(cArray);
//        List<String> eList = Arrays.asList(eArray);
//        List<ModelConvert> convertList = Arrays.asList(converts);
//        Map map = new HashMap();
//        if(StringUtils.isNotEmpty(command)){
//            map.put("command", command);
//        }
//        if(StringUtils.isNotEmpty(packageName)){
//            map.put("packageName", packageName);
//        }
//        if(StringUtils.isNotEmpty(packagePlanName)){
//            map.put("packagePlanName", packagePlanName);
//        }
//        if(StringUtils.isNotEmpty(beginDate)){
//            map.put("beginDate", beginDate);
//        }
//        if(StringUtils.isNotEmpty(endDate)){
//            map.put("endDate", endDate);
//        }
//
//        List<AssetInvestVo> list = assetInvestService.getList(map);
//
//        String serverDir = request.getServletContext().getRealPath("/") + "admin/export/";
//        //String excelFilePath=ExcelUtils.export(allList,serverDir);
//        String excelFilePath = ExcelUtils.export("用户邀请收益列表", cList, eList, convertList, list, serverDir);
//
//        HashMap ret = Message.OK;
//        ret.put("file", "export/" + excelFilePath);
//        return ret;
//    }
}
